package leetcode.tencent;

import java.util.Stack;

/**
 * @author Cheng Jun
 * Description: 给定一个字符串，每个单词用空格字符分开，将整个字符串反转。
 * the sky is blue
 * blue is sky the
 * @version 1.0
 * @date 2021/11/16 17:13
 */
public class reverseStr {

    public static void main(String[] args) {
        StringBuilder stringBuilder = new StringBuilder();
        String str = "the sky is blue";
        Stack<String> stack = new Stack<>();
        for (String s : str.split(" ")) {
            stack.push(s);
        }
        while (!stack.isEmpty()) {
            stringBuilder.append(stack.pop());
            if (!stack.isEmpty()) stringBuilder.append(" ");
        }
        System.out.println(stringBuilder);
    }
}
